<template>
  <CommonPage :show-header="false">
    <article class="margin-top-sm flex  flex-column flex-sub">
      <section style="display: flex;justify-content: space-between;margin-bottom: 10px">
        <div style="display: flex">
          <!--          <StatusSelect v-model:value="andParams.status" @on-select="search"></StatusSelect>-->
          <!--          <SortSelect v-model:value="sortKey" @on-select="search"></SortSelect>-->
          <SortSelect2 v-model:value="sortKey" @on-select="search"></SortSelect2>
        </div>
        <div>
          <SearchInput v-model:value="searchKey" @change="search" :loading="loading" placeholder="ID/用户名"></SearchInput>
        </div>
      </section>
      <section  style="overflow:hidden" class="flex flex-sub radius-lg bg-white  padding-tb-sm">
          <CurdTable ref="tableRef"
                     :get-data="api.admin.formalList"
                     :columns="columns" :and-params="andParams" :or-params="orParams" :order-params="orderParams">
          </CurdTable>
      </section>
    </article>
  </CommonPage>
</template>

<script setup lang="ts">
import CommonPage from "@/components/page/CommonPage.vue";
import api from "@/api";
import {h, onMounted, ref} from "vue";
import SearchInput from "@/components/common/input/SearchInput.vue";
import CurdTable from "@/components/common/table/CurdTable.vue";
import {NAvatar, NEllipsis, NText} from "naive-ui";
import CultureSelect from "@/components/example/select/CultureSelect.vue";
import SexSelect from "@/components/example/select/SexSelect.vue";
import myMoment from "@/utils/common/myMoment";
import SortSelect2 from "@/components/example/select/SortSelect2.vue";
import DepartmentSelect from "@/components/example/select/DepartmentSelect.vue";
import {imagePathPrefix} from '~/settings'
const tableRef = ref()
const searchKey = ref('')
const sortKey = ref('2')
const loading = ref(false)


const prefix =imagePathPrefix
const columns = [
  {title: 'ID', key: 'id', width: 2, ellipsis: {tooltip: true}},

  {
    title: '头像', key: 'avatar', width:2, ellipsis: {tooltip: true},align: 'center',
    render(row: any) {
      return h(NAvatar, {
        width: 100,
        src: prefix+row.avatar || "https://www.zzjtpp.top/blogAPI/uploadFile/%E5%A4%B4%E5%83%8F.bmp",
        round: true
      })
    }
  },
  {
    title: '用户名', key: 'username', width: 5, ellipsis: {tooltip: true}, align: 'center',
    render(row: any) {
      return h(NText, {style: {fontSize: '16px'}}, {default: () => row.username})
    }
  },
  {
    title: '建档时间', key: 'createTime', width: 5, ellipsis: {tooltip: true}, align: 'center',
    render(row: { [x: string]: any; }) {
      return h("div", {}, [
        h("div", {style: {fontSize: '14px'}}, [h(NEllipsis, {}, {default: () =>myMoment(row?.createTime).format("MMMDo HH:mm") })]),
        h(NText, {depth: '3'}, {default: () => myMoment(row?.createTime).startOf('minute').fromNow() }),
      ])
    }
  },
]
/** QueryBar筛选参数（可选） */
const orParams = ref({
  username: '',
  id: '',
})
/** 补充参数（可选） */
const andParams = ref({

})
/** 排序参数(可选）*/
const orderParams = ref({
  createTime:''
})
onMounted(() => {
  search()
})

const search = async () => {
  loading.value = true
  Object.keys(orParams.value).forEach((key: any) => {
    //@ts-ignore
      orParams.value[key] = `%${searchKey.value}%`
  })
  if (sortKey.value === '1') {
    orderParams.value.createTime='1'
  }else if(sortKey.value==='2'){
    orderParams.value.createTime='2'
  }else {
    orderParams.value.createTime=''
  }
  await tableRef.value.handleSearch()
  loading.value = false
}

</script>

<style scoped>

</style>